package com.frejoys.admin.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.common.auth.AuthRuleAddDto;
import com.frejoys.common.dto.common.auth.AuthRuleUpDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.util.RequestUtil;
import com.frejoys.common.vo.common.auth.AuthRuleMenuVo;
import com.frejoys.common.vo.common.auth.AuthRuleVo;
import com.frejoys.service.AuthRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "权限", description = "权限")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixAdmin)
@Authorization(Authority.Private)
public class AdminAuthRuleController {

    private final AuthRuleService authRuleService;

    @Operation(summary = "创建权限")
    @PostMapping("/auth/rule/addInfo")
    public Result authRuleAddInfo(@RequestBody @Validated AuthRuleAddDto dto) {
        authRuleService.addInfo(dto);
        return Result.success();
    }

    @Operation(summary = "修改权限")
    @PostMapping("/auth/rule/upInfo")
    public Result authRuleUpInfo(@RequestBody @Validated AuthRuleUpDto dto) {
        authRuleService.upInfo(dto);
        return Result.success();
    }

    @Operation(summary = "权限列表")
    @PostMapping("/auth/rule/list")
    public Result<List<AuthRuleVo>> authRuleList() {
        return Result.success(authRuleService.listInfo(RequestUtil.userId()));
    }

    @Operation(summary = "我的菜单 - 两级")
    @PostMapping("/auth/rule/menu")
    public Result<List<AuthRuleMenuVo>> authRuleMenu() {
        return Result.success(authRuleService.listMenu(RequestUtil.userId()));
    }

    @Operation(summary = "全部菜单 - 两级")
    @PostMapping("/auth/rule/all")
    public Result<List<AuthRuleMenuVo>> authRuleAll() {
        return Result.success(authRuleService.listAll());
    }
}
